module.exports = (app) => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;

  const SpuSchema = new Schema({
    spuName: {
      type: String,
      required: true,
    },
    description: {
      type: String,
      required: true,
    },
    tmId: {
      type: Schema.Types.ObjectId,
      required: true,
    },
    category3Id: {
      type: Schema.Types.ObjectId,
      required: true,
    },
    spuImageList: [
      {
        type: Schema.Types.ObjectId,
        ref: "ImageList",
      },
    ],
    spuSaleAttrList: [
      {
        type: Schema.Types.ObjectId,
        ref: "SpuSaleAttrs", // 关联 SpuSaleAttrs 表，然后可以联表查询 populate
      },
    ],
    isAdmin: {
      type: Boolean,
      default: false,
    },
  });

  return mongoose.model("Spu", SpuSchema, "Spu");
};
